/*
 * Copyright (c) 2010 Andy Aspell-Clark
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */
package uk.org.aspellclark.agenedb.view;

import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;

public class LayoutUtils {

	public enum Layout {
		WidthFill_HeightFill, WidthWrap_HeightWrap, WidthWrap_HeightFill, WidthFill_HeightWrap;

		public void applyLinearLayoutParams(View linearlayout) {
			applyLinearLayoutParamsTo(this, linearlayout);
		}

		public void applyTableLayoutParams(View row) {
			applyTableLayoutParamsTo(this, row);
		}

		public void applyTableRowParams(View cell) {
			applyTableRowLayoutParamsTo(this, cell);
		}

		public void applyViewGroupParams(View component) {
			applyViewGroupLayoutParamsTo(this, component);
		}

	}

	private static void applyLinearLayoutParamsTo(Layout layout, View view) {

		switch (layout) {
		case WidthFill_HeightFill:
			view.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
					LinearLayout.LayoutParams.FILL_PARENT));
			break;
		case WidthFill_HeightWrap:
			view.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
					LinearLayout.LayoutParams.WRAP_CONTENT));
			break;
		case WidthWrap_HeightFill:
			view.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
					LinearLayout.LayoutParams.FILL_PARENT));
			break;
		case WidthWrap_HeightWrap:
			view.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
					LinearLayout.LayoutParams.WRAP_CONTENT));
			break;
		}

	}

	private static void applyTableLayoutParamsTo(Layout layout, View view) {

		switch (layout) {
		case WidthFill_HeightFill:
			view.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT,
					TableLayout.LayoutParams.FILL_PARENT));
			break;
		case WidthFill_HeightWrap:
			view.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT,
					TableLayout.LayoutParams.WRAP_CONTENT));
			break;
		case WidthWrap_HeightFill:
			view.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT,
					TableLayout.LayoutParams.FILL_PARENT));
			break;
		case WidthWrap_HeightWrap:
			view.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT,
					TableLayout.LayoutParams.WRAP_CONTENT));
			break;
		}

	}

	private static void applyTableRowLayoutParamsTo(Layout layout, View view) {

		switch (layout) {
		case WidthFill_HeightFill:
			view.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,
					TableRow.LayoutParams.FILL_PARENT));
			break;
		case WidthFill_HeightWrap:
			view.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT,
					TableRow.LayoutParams.WRAP_CONTENT));
			break;
		case WidthWrap_HeightFill:
			view.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
					TableRow.LayoutParams.FILL_PARENT));
			break;
		case WidthWrap_HeightWrap:
			view.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
					TableRow.LayoutParams.WRAP_CONTENT));
			break;
		}

	}

	private static void applyViewGroupLayoutParamsTo(Layout layout, View view) {

		switch (layout) {
		case WidthFill_HeightFill:
			view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
					ViewGroup.LayoutParams.FILL_PARENT));
			break;
		case WidthFill_HeightWrap:
			view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
					ViewGroup.LayoutParams.WRAP_CONTENT));
			break;
		case WidthWrap_HeightFill:
			view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
					ViewGroup.LayoutParams.FILL_PARENT));
			break;
		case WidthWrap_HeightWrap:
			view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
					ViewGroup.LayoutParams.WRAP_CONTENT));
			break;
		}

	}

}// end class LayoutUtils
